#!/usr/bin/python2.5
"""This is the main file for GeoTree demo.
It includes classes for the first page and to fetch JSON data for tile.
"""

__author__ = 'Artem Dudarev'
__licence__ = 'Apache 2.0'
__date__ = 'Mon 15 Mar 2010 10:03:46 AM EET'

import os

from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app

from geotree.geotree import GeoTree, Point


class GetTiles(webapp.RequestHandler):
    def get(self):
        center = self.request.get('c').strip()
        tiles = GeoTree.fetch_around_tile(center)
        self.response.out.write(tiles);


class MainHandler(webapp.RequestHandler):
    def get(self):

        path = os.path.join(os.path.dirname(__file__), 'templates/index.html')
        self.response.out.write(template.render(path,{}))


application = webapp.WSGIApplication([
                                    ('/', MainHandler),
                                    ('/t/', GetTiles),
                                    ],
                                   debug=True)

def main():
  run_wsgi_app(application)

if __name__ == '__main__':
    main()
